package com.xiao.wiki.job;

import com.xiao.wiki.service.EbookSnapshotService;
import com.xiao.wiki.util.SnowFlake;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.slf4j.MDC;
import org.springframework.scheduling.annotation.Scheduled;
import org.springframework.stereotype.Component;

import javax.annotation.Resource;

/**
 * @author ：降蓝
 * @description：电子快照的定时任务
 * @date ：2022/9/21 22:19
 */
@Component
public class EbookSnapshotJob {
    private static final Logger LOG = LoggerFactory.getLogger(EbookSnapshotJob.class);

    @Resource
    SnowFlake snowFlake;

    @Resource
    EbookSnapshotService ebookSnapshotService;



    // 每30分钟执行一次
    @Scheduled(cron = "0 0/30 * * * ?")
    public void cron()  {
        // 增加日志流水号
        MDC.put("LOG_ID", String.valueOf(snowFlake.nextId()));
        LOG.info("电子快照更新开始");
        long start = System.currentTimeMillis();
        ebookSnapshotService.genSnapshot();
        LOG.info("更新电子快照数据结束，耗时：{}毫秒", System.currentTimeMillis() - start);
    }
}
